<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /* 
    1. 统计一个字符串中出现次数最多的字符和出现次数
    */
    const str = "aabbbcccc";
    // console.log(str.split('')); // 分隔每一个字符 ["a","b","d","d".......]

    // 先用  reduce  累加 统计 
    const totalNum = str.split('').reduce((prev, current) => {
      console.log(prev, current); // prev初始值 初始是一个空对象   current 遍历的当前元素
      prev[current] ? prev[current]++ : (prev[current] = 1)
      return prev
    }, {})
    console.log(totalNum);

    //定义一个变量-保存当前最大值的key
    let BigKey = "";
    let BigNum = 0;

    console.log(Object.keys(totalNum));

    /* 
    Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组，
    */

    for (let key of Object.keys(totalNum)) {
      if (totalNum[key] > BigNum) {
        BigNum = totalNum[key]
        console.log(key);
        BigKey = key
      }
    }

    console.log('出现次数最多', BigKey);
    console.log('出现次数是', BigNum);




    // 2.将字符串转成对象
    const url = "http://www.laoli.com?a=1&b=2&c=3"

    let res = url.split("?")[1].split("&")

    console.log(res);
    const result = res.reduce((p, c) => {
      const [key, value] = c.split('=')
      p[key] = value
      return p
    }, {})
    console.log(result);



    // 3. 得到7天以后的时间
    console.log("1", new Date().setDate(new Date().getDate() + 7));

    //得到7天以后的时间
    new Date("2022-10-1 8:00:00");
    new Date(2022, 9, 1, 8, 0, 0, 0);
    new Date(Date.now() + 1000 * 60 * 60 * 24 * 7);



  </script>
</body>

</html>